home *** CD-ROM | disk | FTP | other *** search
- Path: howland.reston.ans.net!psinntp!psinntp!psinntp!psinntp!usenet
- From: grantp@usa.pipeline.com(Pete Grant)
- Newsgroups: comp.lang.c++
- Subject: Re: Symantec 7.2 Hello World Problem
- Date: 24 Mar 1996 15:02:25 GMT
- Organization: Kalevi, Inc.
- Message-ID: <4j3o61$bie@news1.h1.usa.pipeline.com>
- References: <199603232309.HAA22808@public1.guangzhou.gd.cn>
- NNTP-Posting-Host: 38.8.120.9
- X-PipeUser: grantp
- X-PipeHub: usa.pipeline.com
- X-PipeGCOS: (Pete Grant)
- X-Newsreader: Pipeline v3.5.0
-
- On Mar 24, 1996 10:54:14 in article <Re: Symantec 7.2 Hello World Problem>,
- 'Wang TianXing <gztxwang@public1.guangzhou.gd.cn>' wrote:
-
-
- >On Fri, 22 Mar 1996 10:02:55 -0500, Ron Romero <ron.romero@ssds.com>
- >wrote:
- >
- >| I'm having trouble doing a C++ Hello World program with Symantec C++
- 7.2,
- >using output to windows
- >| 3.11 console. It seems like this should be trivial, but it dowsn't
- work. It
- >works with printf,
- >| but cout produces no output.
- >
- >| Here's the code:
- >
- >| -----Cut Here------------
- >| #include <iostream.h>
- >| #include <stdio.h>
- >
- >| main()
- >| {
- >| cout << "Hello World" << endl;
- >
- >| printf("Goodbye World\n");
- >| }
- >| -----Cut Here------------
- >
- >| This produces "Goodbye World" on the first line of the console window.
-
- >
- >| Any ideas? Am I just not linking right?
- >
- >| Ron Romero
- >
- >Generally, you cannot mix cout and printf(), because both of them are
- >bufferring outputs.
- >
- >So, if you remove the printf(...), you'll see "Hello World" on the
- >console. If you insist to mix cout and printf(), try this:
- >
- >#include <iostream.h>
- >#include <stdio.h>
- >
- >int main()
- >{
- > cout << "Hello World" << endl;
- > cout.flush();
- > printf( "Goodbye World\n" );
- > fflush( stdout );
- > return 0;
- >}
- >
- >I believe this question is in the FAQ:
- >
- > ftp://rtmf.mit.edu/pub/usenet-by-group/comp.lang.c++/*
- >
- >
- >---
- >Wang TianXing
- >
- >
- I don't know what the answer is, but I don't think Wang's answer
- solves the problem either. The only problem with mixing iostreams
- and stdio is that the order in which the characters appear in the
- output medium is unspecified. This may result in garbled or non-
- sense output.
-
- In the sample case, however, the Ron uses "<< endl;" which flushes
- the iostream buffer, then calls printf. Both outputs should
- appear on the screen as Ron had intended. Adding cout.flush() will
- not accomplish any additional behavior. As far as I can tell
- by looking at the posted sample, Symantec's compiler/linker
- seems to be incorrect.
-
- On the subject of mixing iostream and stdio, there's a better(?)
- way: Call ios::sync_with_stdio() once in your program and from
- there on until the program terminates, mixing the two should be
- no problem.
- --
- Pete Grant
- Kalevi, Inc.
- Software Engineering & development
-